import Vue from 'vue'
import VueRouter from 'vue-router'
// import HomeView from '../views/HomeView.vue'
import Layout from '../views/layout'
import Login from '../views/Login'
import Home from '../views/Home/index.vue'
import childrenroutes from './routes'




Vue.use(VueRouter)

export const baseRouter = [
  {
    path: '/',
    // name: 'Layout',
    component: Layout,
    // children: childrenroutes,
    meta: {
      title: '首页',
      // icon: 'icon-shouye',
      islogin: true
    },
    children: [
      {
        path: '/',
        name: 'home',
        component: Home,
        meta: {
          title: '首页',
          icon: 'icon-shouye'
        }
      }

    ]
  },
  {
    path: '*',
    redirect: '/'
  }
]

const routes = [

  {
    path: '/login',
    name: 'Login',
    component: Login
  },
]


// 解决ElementUI导航栏中的vue-router在3.0版本以上重复点菜单报错问题
// const originalPush = VueRouter.prototype.push
// VueRouter.prototype.push = function push(location) {
//   return originalPush.call(this, location).catch(err => err)
// }


const createRouter = () => new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes
})

const router = createRouter()
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // the relevant part
}


// 解决重复点击导航时，控制台出现报错
const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(to) {
  return VueRouterPush.call(this, to).catch(err => err)
}


export default router
